package com.example.user.customviewdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextClock;

import com.example.user.customviewdemo.apidemo.animation.BouncingBallsActivity;
import com.example.user.customviewdemo.camera.CameraActivity;
import com.example.user.customviewdemo.canvasview.CanvasViewActivity;
import com.example.user.customviewdemo.draggridview.DragGridViewActivity;
import com.example.user.customviewdemo.drawerlayoutmenu.ContextMenuActivity;
import com.example.user.customviewdemo.drawerlayoutmenu.DrawerLayoutActivity;
import com.example.user.customviewdemo.drawerlayoutmenu.XmlMenuActivity;
import com.example.user.customviewdemo.drawing.bessel.BesselActivity;
import com.example.user.customviewdemo.drawing.canvas.CanvasActivity;
import com.example.user.customviewdemo.drawing.colorfilter.LightingColorFilterActivity;
import com.example.user.customviewdemo.drawing.colorfilter.PorterDuffColorFilterActivity;
import com.example.user.customviewdemo.drawing.geometry.DrawGeometryActivity;
import com.example.user.customviewdemo.drawing.matrix.GestureImageViewActivity;
import com.example.user.customviewdemo.drawing.matrix.MatrixActivity;
import com.example.user.customviewdemo.drawing.paint.ColorMatrixActivity;
import com.example.user.customviewdemo.drawing.paint.PaintActivity;
import com.example.user.customviewdemo.drawing.pathandtext.PathAndTextActivity;
import com.example.user.customviewdemo.drawing.range.RegionActivity;
import com.example.user.customviewdemo.drawing.shader.BitmapShaderActivity;
import com.example.user.customviewdemo.drawing.shader.OtherShaderActivity;
import com.example.user.customviewdemo.drawing.text.TextActivity;
import com.example.user.customviewdemo.drawing.xfermode.AvoidXfermodeActivity;
import com.example.user.customviewdemo.drawing.xfermode.CircleWaterActivity;
import com.example.user.customviewdemo.drawing.xfermode.HeartMapActivity;
import com.example.user.customviewdemo.drawing.xfermode.PorterDuffXfermodeActivity;
import com.example.user.customviewdemo.drawing.xfermode.RevertBitmapActivity;
import com.example.user.customviewdemo.drawing.xfermode.RubberActivity;
import com.example.user.customviewdemo.drawing.xfermode.WaveNameActivity;
import com.example.user.customviewdemo.emoji.RichEditTextActivity;
import com.example.user.customviewdemo.event.EventActivity;
import com.example.user.customviewdemo.github.CircularProgressViewActivity;
import com.example.user.customviewdemo.index.IndexSideBarActivity;
import com.example.user.customviewdemo.layerlist.LayerListActivity;
import com.example.user.customviewdemo.layoutanimation.LayoutAnimationActivity;
import com.example.user.customviewdemo.layoutanimation.gridlayoutanimation.GridLayoutAnimationActivity;
import com.example.user.customviewdemo.popupwindow.PopupWindowActivity;
import com.example.user.customviewdemo.pulltorefresh.PullToRefreshListViewActivity;
import com.example.user.customviewdemo.recyclerview.RecyclerViewActivity;
import com.example.user.customviewdemo.removeitemlistview.RemoveItemListViewActivity;
import com.example.user.customviewdemo.shape.ShapeActivity;
import com.example.user.customviewdemo.slideletelistview.dellistview.DelListViewActivity;
import com.example.user.customviewdemo.slideletelistview.merge.MergeActivity;
import com.example.user.customviewdemo.slideletelistview.scroll.ScrollActivity;
import com.example.user.customviewdemo.slideletelistview.scroller.MyScrollerListViewActivity;
import com.example.user.customviewdemo.swiperefreshlayout.SwipeRefreshLayoutActivity;
import com.example.user.customviewdemo.tabviewpager.TabViewPagerActivity;
import com.example.user.customviewdemo.test.DeleteEditTextActivity;
import com.example.user.customviewdemo.test.StepActivity;
import com.example.user.customviewdemo.test.TestCircleImageViewActivity;
import com.example.user.customviewdemo.test.TestMyProgressActivity;
import com.example.user.customviewdemo.test.TestSNSActivity;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private String name ;
    @Bind(R.id.text_clock)
    TextClock textClock;
    @Bind(R.id.listview)
    ListView mListView;

    private View rootView;

    private ArrayList<String> data = new ArrayList<>();
    private ArrayList<Class> classes = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // full(true);
       /* getSupportActionBar().hide();
        full(true);*/
        //full(true); //隐藏状态栏和导航栏
        this.setContentView(R.layout.activity_main);//把光标异地用到layout上

        ButterKnife.bind(this);
        // 设置12时制显示格式EEEE, MMMM dd, yyyy h:mm:ss aa
        textClock.setFormat12Hour("yyyy-MM-dd hh:mm:ss, EEEE");
        // 设置24时制显示格式
        //textClock.setFormat24Hour("yyyy-MM-dd hh:mm, EEEE");

        addData();

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
        mListView.setAdapter(adapter);
        mListView.setOnItemClickListener(this);
    }

    /**
     *  控制导航栏的显示与隐藏
     * @param enable
     */
    private void full(boolean enable) {
        if (enable) {
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN;
            getWindow().setAttributes(lp);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            //以上代码等效于getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN|WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        } else {
            WindowManager.LayoutParams attr = getWindow().getAttributes();
           // attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);//这个可以解除全屏
            getWindow().setAttributes(attr);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);//显示导航栏
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

       /* int action = ev.getAction();
        switch (action){
           case  MotionEvent.ACTION_DOWN:
               full(true);
            break;
            case MotionEvent.ACTION_UP:
                full(false);
            break;
        }*/
        return super.dispatchTouchEvent(ev);
    }

    /**
     * 添加数据源
     */
    private void addData() {
        add("xml  shape形状", ShapeActivity.class);
        add("xml  layer-list图层", LayerListActivity.class);
        add("自定义控件之绘图篇绘制基本几何图形", DrawGeometryActivity.class);
        add("自定义控件之绘图篇:绘制路径及文字", PathAndTextActivity.class);
        add("自定义控件之绘图篇:绘制区域", RegionActivity.class);
        add("自定义控件之绘图篇:canvas变换与操作", CanvasActivity.class);

        add("自定义控件之绘图篇:drawText()详解", TextActivity.class);
        add("自定义控件之绘图篇:贝塞尔曲线", BesselActivity.class);
        add("自定义控件之绘图篇:paint函数大汇总", PaintActivity.class);
        add("自定义控件之绘图篇:Paint之ColorFilter(ColorMatrixColorFilter)", ColorMatrixActivity.class);
        add("自定义控件之绘图篇:Paint之ColorFiter(LightingColorFilter)", LightingColorFilterActivity.class);
        add("自定义控件之绘图篇:Paint之ColorFiter(PorterDuffColorFilter)", PorterDuffColorFilterActivity.class);
        add("自定义控件之绘图篇:Paint之Xfermode(AvoidXfermode)", AvoidXfermodeActivity.class);
        add("自定义控件之绘图篇:Paint之Xfermode(PorterDuffXfermode)", PorterDuffXfermodeActivity.class);
        add("自定义控件之绘图篇:Paint之Xfermode(PorterDuffXfermode SRC_IN)实现倒影效果", RevertBitmapActivity.class);
        add("自定义控件之绘图篇:Paint之Xfermode(PorterDuffXfermode SRC_OUT)实现橡皮擦效果", RubberActivity.class);
        add("自定义控件之绘图篇:Paint之Xfermode(PorterDuffXfermode DST_IN)实现波纹签名效果", WaveNameActivity.class);
        add("自定义控件之绘图篇:Paint之Xfermode(PorterDuffXfermode DST_IN)实现心电图效果", HeartMapActivity.class);
        add("自定义控件之绘图篇:Paint之Xfermode(PorterDuffXfermode DST_IN)实现灌水效果", CircleWaterActivity.class);
        add("自定义控件之绘图篇:Paint之shader(BitmapShader)", BitmapShaderActivity.class);
        add("自定义控件之绘图篇:Paint之shader(其他三个shader)", OtherShaderActivity.class);
        add("自定义控件之绘图篇:Paint之shader(Matrix详解)", MatrixActivity.class);
        add("自定义手势ImageView", GestureImageViewActivity.class);
        add("自定义progressbar", TestMyProgressActivity.class);
        add("仿QQ空间列表界面", TestSNSActivity.class);
        add("自定义CircleImageView", TestCircleImageViewActivity.class);
        add("自定义带有删除按钮的EditText", DeleteEditTextActivity.class);
        add("陈志清  StepView", StepActivity.class);
        add("自定义控件之容器动画LayoutAnimation", LayoutAnimationActivity.class);
        add("自定义控件之容器动画GridLayoutAnimation", GridLayoutAnimationActivity.class);
        add("RecyclerView", RecyclerViewActivity.class);
        add("github CircularProgressView", CircularProgressViewActivity.class);
        add("鱼眼索引控件", IndexSideBarActivity.class);
        add("android事件分发机制", EventActivity.class);
        add("ListView item 滑动删除之（merge和LayoutInflater）", MergeActivity.class);
        add("ListView item 滑动删除之（scroll）", ScrollActivity.class);
        add("可滑动删除item的ListView 一（无scoller版）", DelListViewActivity.class);
        add("可滑动删除item的ListView 二（scoller封装版版）", MyScrollerListViewActivity.class);
        add("可滑动删除item的ListView 三 ", RemoveItemListViewActivity.class);
        add("拖拽排序GridView", DragGridViewActivity.class);
        add("android原生下拉刷新SwipeRefreshLayout", SwipeRefreshLayoutActivity.class);
        add("PullToRefreshListViewActivity", PullToRefreshListViewActivity.class);
        add("android原生侧滑菜单DrawerLayout和OptionMenu的使用", DrawerLayoutActivity.class);
        add("xml生成菜单和子菜单并显示在title栏", XmlMenuActivity.class);
        add("ContextMenu", ContextMenuActivity.class);
        add("PopupWindow的使用", PopupWindowActivity.class);
        add("canvas画图练习", CanvasViewActivity.class);
        add("自己封装的带tab页的viewpager", TabViewPagerActivity.class);
        add("EditText添加emoji表情", RichEditTextActivity.class);
        add("录像demo", CameraActivity.class);
        add("api demo  animation 之 BoundingBalls", BouncingBallsActivity.class);
    }

    private void add(String describle, Class z) {
        data.add(describle);
        classes.add(z);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent intent = new Intent(this, classes.get(i));
        startActivity(intent);
    }

}
